# -*- coding: utf-8 -*-
import scrapy
import requests
from douban.items import DoubanItem

class DoubanInfoSpider(scrapy.Spider):
    name = 'douban_info'
    allowed_domains = ['www.douban.com']

    def start_requests(self):
        urls = [
            'https://movie.douban.com/subject/27098888/?from=subject-pag'
        ]

        for url in urls:
            yield scrapy.Request(url=url,callback=self.parse)

    def parse(self, response):
        title = response.css("h1 span::text").extract_first()
        comments = response.css("div.comment p span.short::text").extract_first()
        item= DoubanItem(name=title,url=response._url,comments=comments)
        yield item

        for a in response.css("div.recommendations-bd dl dd a"):
            href = a.attrib.get("href",None)

            if href:
                yield scrapy.Request(url=href,callback=self.parse)







